package com.example.spring2303.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class AspectJByAno {

    @Pointcut("execution(* com.example.spring2303.aop.*.*(..))")
    public void myPointCut() {

    }
    @Before("myPointCut()")
    public void myBefore(JoinPoint joinPoint){
        System.out.println("前置通知========");
        System.out.println("前置通知的目标=" + joinPoint.getTarget());
        System.out.println("增强的目标 =" +joinPoint.getSignature().getName() );
    }
    @Around("myPointCut()")
    public Object myAround(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        System.out.println("环绕通知开始=====");
        Object obj = proceedingJoinPoint.proceed();
        System.out.println("环绕通知结束=======");

        return obj;
    }

    @AfterThrowing(value = "myPointCut()",throwing = "e")
    public void myThrowing(JoinPoint joinPoint,Throwable e){
        System.out.println("异常通知=====");
        System.out.println(e.getMessage());

    }

    @AfterReturning("myPointCut()")
    public void myAfterReturning(JoinPoint joinPoint){
        System.out.println("后置返回通知=======");
    }

    @After("myPointCut()")
    public  void myAfter() {
        System.out.println("后置最终通知======");
    }
}
